home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / cleanUpScene.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  32.8 KB  |  1,107 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. // Alias|Wavefront Script File
  19. //
  20. // Creation Date:  
  21. // Author:         
  22. //
  23. //
  24. //  Procedure Name:
  25. //      cleanUpScene
  26. //
  27. //  Description:
  28. //      This procedure invokes the clean up scene operations.
  29. //
  30. //  Input Arguments:
  31. //
  32. //  Return Value:
  33. //      None.
  34. //
  35.  
  36. global proc string[] listEmptyGroups( ) 
  37. //
  38. //    Lists groups with no relatives or connections,
  39. //    and supplies them to the calling proc to
  40. //    do with as needed.
  41. //
  42. {
  43.     string $obj;
  44.     string $unused[];
  45.     string $xforms[] = `ls -transforms -leaf`;
  46.     for( $obj in $xforms ) {
  47.         if( size( listRelatives("-c", $obj) ) == 0 ) {
  48.             if( `objectType $obj` == "transform") {
  49.                 string $conn[] = `listConnections($obj)`;
  50.                 if( size( $conn ) == 0 ) {
  51.                     $unused[size($unused)] = $obj;
  52.                 } else if( (size( $conn ) == 1)
  53.                        &&  (`objectType $conn[0]` == "displayLayer") ) {
  54.                     $unused[size($unused)] = $obj;
  55.                 } else if( (size( $conn ) == 1)
  56.                        &&  (`objectType $conn[0]` == "renderLayer") ) {
  57.                     $unused[size($unused)] = $obj;
  58.                 }
  59.             }
  60.         }
  61.     }
  62.     return $unused;
  63. }
  64.  
  65. global proc deleteEmptyGroups( ) 
  66. //
  67. //    Deletes anything returned by listEmptyGroups,
  68. //    until the list itself is empty
  69. //
  70. {
  71.     int $i;
  72.     string $unused[] = `listEmptyGroups`;
  73.     int $numTransf = size(`ls -transforms`);
  74.     int $numUnused = size($unused);
  75.     while ( $numUnused > 0 ) {
  76.         for ($i = 0; $i < size($unused); $i++) {
  77.             deleteIfNotReferenced( $unused[$i] );
  78.         }
  79.         $unused = `listEmptyGroups`;
  80.  
  81.         // 132335: need to avoid infinite loop possibility
  82.         // if referenced files - nothing deleted.
  83.         if (size($unused) == $numUnused &&
  84.             size(`ls -transforms`) == $numTransf) {
  85.             break;
  86.         } else {
  87.             $numUnused = size($unused);
  88.             $numTransf = size(`ls -transforms`);
  89.         }
  90.     }
  91. }
  92.  
  93. global proc deleteEmptyLayers(string $type)
  94. //
  95. // If $type == "Display" then delete display layers
  96. // If $type == "Render" then delete render layers
  97. //
  98. {
  99.     string $objectType, $layer;
  100.     string $layerArray[], $layerContents[];
  101.  
  102.     if ("Display" == $type) {
  103.         $objectType = "displayLayer";
  104.     } else {
  105.         $objectType = "renderLayer";
  106.     }
  107.  
  108.     //    Get all layers of the appropriate type.
  109.     //
  110.     $layerArray = `ls -type $objectType`;
  111.  
  112.     //    Determine the contents of each layer. Ignore default layers.
  113.     //
  114.     int $index = 0;
  115.     for ($layer in $layerArray) {
  116.  
  117.         //    Ignore default layers. Default layers have an id of 0.
  118.         //
  119.         if (0 < `getAttr ($layer + ".identification")`) {
  120.             if ("Display" == $type) {
  121.                 $layerContents = `editDisplayLayerMembers -query $layer`;
  122.             } else if ("Render" == $type) {
  123.                 $layerContents = `editRenderLayerMembers -query $layer`;
  124.             }
  125.             if (0 == size($layerContents)) {
  126.                 //
  127.                 //    This layer has nothing in it. Delete it.
  128.                 //
  129.                 deleteIfNotReferenced ($layer);
  130.             }
  131.         }
  132.     }
  133. }
  134.  
  135. proc getAllParents(string $node, string $resultParents[])
  136. //
  137. // Description:
  138. //      Procedure to find all the parents at all levels above the specified
  139. //      node. The parent names will be appended to resultParents.
  140. //
  141. // Arguments:
  142. //      node            Name of node to get parents for.
  143. //      resultParents   Array to append parent names to.
  144. //
  145. // Author:
  146. //      cdt (March 2002)
  147. //
  148. {
  149.     string $parents[] = `listRelatives -allParents -fullPath $node`;
  150.  
  151.     for ($parent in $parents) {
  152.         // Append to the end of the list.
  153.         $resultParents[size($resultParents)] = $parent;
  154.  
  155.         getAllParents($parent, $resultParents);
  156.     }
  157. }
  158.  
  159. global proc deleteUnusedConstraints()
  160. //
  161. // Description:
  162. //  Deletes constraints that are not constraining any objects.
  163. //
  164.     string $constraintTypes[] = { "pointConstraint",
  165.                                   "aimConstraint",
  166.                                   "orientConstraint",
  167.                                   "parentConstraint",
  168.                                   "scaleConstraint",
  169.                                   "normalConstraint",
  170.                                   "tangentConstraint",
  171.                                   "geometryConstraint"};
  172.     for ($typ in $constraintTypes) {
  173.         string $constraints[] = `ls -type $typ`;
  174.  
  175.         // Is the constraint driving anything?
  176.         //
  177.         for ($constraint in $constraints) {
  178.             // are there any outgoing connections?
  179.             //
  180.             string $conns[] = `listConnections -s 0 -d 1 $constraint`;
  181.  
  182.             int $deleteIt = 1;
  183.             for ($conn in $conns) {
  184.                 // ignore outgoing connections that lead to this node itself
  185.                 // (constraints connect their weight attribute to a dynamic weight
  186.                 // attribute)
  187.                 //
  188.                 if ($conn != $constraint) {
  189.                     $deleteIt = 0;
  190.                     break;
  191.                 }
  192.             }
  193.             if ($deleteIt) {
  194.                 deleteIfNotReferenced($constraint);
  195.             }
  196.         }
  197.     }
  198. }
  199.  
  200. global proc deleteUnusedPairBlends()
  201. //
  202. // Description:
  203. //  Deletes pairBlends that meet the following criteria:
  204. //   1. have no outputs, or
  205. //   2. have no connections to input2    
  206. //
  207.     string $pairBlends[] = `ls -type pairBlend`;
  208.     for ($pairBlend in $pairBlends) {
  209.         int $deleteIt = 0;
  210.         string $conns[] = `listConnections -s 0 -d 1 $pairBlend`;
  211.         if (0 == size($conns)) {
  212.             $deleteIt = 1;
  213.         } else {
  214.             string $inputs[] = `pairBlend -q -input2 $pairBlend`;
  215.             if (0 == size($inputs)) {
  216.                 $deleteIt = 1;
  217.             }
  218.         }
  219.         if ($deleteIt) {
  220.             deleteIfNotReferenced($pairBlend);
  221.         }
  222.     }
  223. }
  224.  
  225. global proc deleteUnusedLocators()
  226. // 
  227. // Desription:
  228. //    Deletes those locator objects that don't have connections
  229. //    to either their shape or transform nodes. 
  230. //
  231. {
  232.     int $i, $j, $shapeConnections, $parentConnections;
  233.     string $nodeList[] = `ls -typ locator`;
  234.     string $connectionList[];
  235.     string $parent[];
  236.  
  237.     for ($i = 0; $i < size($nodeList); $i++) {
  238.         // Check if the locator shape is connected
  239.         //
  240.         string $locatorShape = $nodeList[$i];
  241.  
  242.         $connectionList = `listConnections $locatorShape`;
  243.         $numConnections = size($connectionList);
  244.         if ($numConnections == 0)
  245.         {
  246.             // Check if the locator transform is connected
  247.             //
  248.             clear($parent);
  249.             getAllParents($nodeList[$i], $parent);
  250.             int $parentOK = true;
  251.             for($j = 0; $j < size($parent); $j++)
  252.             {
  253.                 string $parentNode = $parent[$j];
  254.                 $connectionList = `listConnections $parentNode`;
  255.                 $parentConnections = size($connectionList);
  256.                 if ($parentConnections != 0)
  257.                 {
  258.                     $parentOK = false;
  259.                     break;
  260.                 }
  261.                 
  262.             }
  263.             if ($parentOK)
  264.             {
  265.                 for($j=0;$j<size($parent);$j++)
  266.                 {
  267.                     $parentNode = $parent[$j];
  268.  
  269.                     // Don't remove the locator transform if there are  
  270.                     // objects parented under it other than the locator
  271.                     // shape
  272.                     //
  273.                     string $childL[] = `listRelatives -c $parentNode`;
  274.                     if (size($childL) > 1)
  275.                         continue;
  276.                     
  277.                     deleteIfNotReferenced( $parentNode );
  278.                 }
  279.             }
  280.         }
  281.     }
  282. }
  283.  
  284.  
  285. //
  286. //    cleanUpScene:
  287. //        $option = 1: does the cleanup operation
  288. //        $option = 2: option window for cleanup
  289. //        $option = 3: cleanup operation for everything regardless of options
  290. //
  291. global proc cleanUpScene (int $option)
  292. {
  293.     if ($option == 1) {    
  294.         // Do the cleanup
  295.         setOptionVars (false);
  296.         performCleanUpScene();
  297.     } else if ($option == 2) {
  298.         // Option window for the cleanup work
  299.         cleanUpOptions();
  300.     } else if ($option == 3) {
  301.         performCleanUpSceneForEverything();
  302.     }
  303. }
  304.  
  305.  
  306. //
  307. //    invokes the MEL procs to start deleting the unused database.
  308. //
  309. global proc performCleanUpScene ()
  310. {
  311.     // Confirm that a cleanup is desired (since this is not undoable)
  312.     string $result = `confirmDialog 
  313.         -title "Verifying Action"
  314.         -message "Optimize current scene size?\nThis action is not undoable." 
  315.         -button "OK" -button "Cancel"`; 
  316.     
  317.     if (!`about -batch` && $result != "OK") {
  318.         return;
  319.     }
  320.  
  321.     print "\n";
  322.  
  323.     if (`optionVar -query nurbsSrfOption`) {
  324.         print "Removing invalid nurbs surfaces\n";
  325.         print "-------------------------------\n";
  326.         deleteInvalidNurbs(0);
  327.  
  328.         // These nodes can be considered "invalid" 
  329.         // if they have no connections.  The list is
  330.         // far from complete; we'll add to it as needed.
  331.         //
  332.         deleteUnusedCommon( "stitchSrf", 0 );
  333.         deleteUnusedCommon( "rebuildSurface", 0 );
  334.         deleteUnusedCommon( "insertKnotSurface", 0 );
  335.         deleteUnusedCommon( "avgNurbsSurfacePoints", 0 );
  336.         print "\n";
  337.     }
  338.  
  339.     if (`optionVar -query nurbsCrvOption`) {
  340.         print "Removing unused nurbs curves\n";
  341.         print "----------------------------\n";
  342.         deleteUnusedInUnusedHierarchy("nurbsCurve", 0);
  343.         print "\n";
  344.     }
  345.  
  346.     if (`optionVar -query locatorOption`) {
  347.         print "Removing unused locators\n";
  348.         print "------------------------\n";
  349.         deleteUnusedLocators();
  350.         print "\n";
  351.     }
  352.  
  353.     if (`optionVar -query ptConOption`) {
  354.         print "Removing unused constraints\n";
  355.         print "---------------------------------\n";
  356.         deleteUnusedConstraints();
  357.         print "\n";
  358.     }
  359.  
  360.     if (`optionVar -query pbOption`) {
  361.         print "Removing unused pairBlends\n";
  362.         print "---------------------------------\n";
  363.         deleteUnusedPairBlends();
  364.         print "\n";
  365.     }
  366.  
  367.     if (`optionVar -query deformerOption`) {
  368.         print "Removing unused deformers\n";
  369.         print "-------------------------\n";
  370.         deleteUnusedDeformers();
  371.         print "\n";
  372.     }
  373.  
  374.     if (`optionVar -query expressionOption`) {
  375.         print "Removing unused expressions\n";
  376.         print "---------------------------\n";
  377.         deleteUnusedExpressions();
  378.         print "\n";
  379.     }
  380.  
  381.     if (`optionVar -query groupIDnOption`) {
  382.         print "Removing unused groupID nodes\n";
  383.         print "-----------------------------\n";
  384.         deleteUnusedCommon("groupId", 1);
  385.         print "\n";
  386.     }
  387.  
  388.     if (`optionVar -query animationCurveOption`) {
  389.         print "Removing unused animation curves\n";
  390.         print "--------------------------------\n";
  391.         deleteUnusedCommon("animCurve", 0);
  392.         print "\n";
  393.     }
  394.  
  395.     if (`optionVar -query clipOption`) {
  396.         print "Removing unused animation clips\n";
  397.         print "-------------------------\n";
  398.         deleteUnusedTrax("clips");
  399.         print "\n";
  400.     }
  401.  
  402.     if (`optionVar -query poseOption`) {
  403.         print "Removing unused animation poses\n";
  404.         print "-------------------------\n";
  405.         deleteUnusedTrax("poses");
  406.         print "\n";
  407.     }
  408.  
  409.     if (`optionVar -query snapshotOption`) {
  410.         print "Removing unused snapshot nodes\n";
  411.         print "------------------------------\n";
  412.         deleteUnusedCommon("snapshot", 1);
  413.         print "\n";
  414.     }
  415.  
  416.     if (`optionVar -query unitConversionOption`) {
  417.         print "Removing unused unit conversion nodes\n";
  418.         print "-------------------------------------\n";
  419.         deleteUnusedCommon("unitConversion", 1);
  420.         deleteUnusedCommon("timeToUnitConversion", 1);
  421.         deleteUnusedCommon("unitToTimeConversion", 1);
  422.         print "\n";
  423.     }
  424.  
  425.     if (`optionVar -query shaderOption`) {
  426.         print "Removing unused rendering nodes\n";
  427.         print "-------------------------------\n";
  428.         MLdeleteUnused();
  429.         print "\n";
  430.     }
  431.  
  432.     if (`optionVar -query cachedOption`) {
  433.         print "Removing cached data in datablocks\n";
  434.         print "----------------------------------\n";
  435.         int $cleared = `clearCache -allNodes`;
  436.         print( "Cleaned out " + $cleared + " datablocks\n");
  437.         print "\n";
  438.     }
  439.  
  440.     if (`optionVar -query transformOption`) {
  441.         print "Removing empty transforms\n";
  442.         print "-------------------------\n";
  443.         deleteEmptyGroups();
  444.         print "\n";
  445.     }
  446.  
  447.     if (`optionVar -query displayLayerOption`) {
  448.         print "Removing empty display layers\n";
  449.         print "-----------------------------\n";
  450.         deleteEmptyLayers("Display");
  451.         print "\n";
  452.     }
  453.  
  454.     if (`optionVar -query renderLayerOption`) {
  455.         print "Removing empty render layers\n";
  456.         print "-----------------------------\n";
  457.         deleteEmptyLayers("Render");
  458.         print "\n";
  459.     }
  460.  
  461.     if (`optionVar -query setsOption`) {
  462.         print "Removing empty sets\n";
  463.         print "-------------------\n";
  464.         deleteUnusedSets();
  465.         print "\n";
  466.     }
  467.  
  468.     if (`optionVar -query partitionOption`) {
  469.         print "Removing empty partitions\n";
  470.         print "-------------------------\n";
  471.         deleteUnusedCommon("partition", 0);
  472.         print "\n";
  473.     }
  474.  
  475.     if (`optionVar -query referencedOption`) {
  476.         print "Removing unused referenced items\n";
  477.         print "--------------------------------\n";
  478.         RNdeleteUnused();
  479.         print "\n";
  480.     }
  481.  
  482.     if (`optionVar -query brushOption`) {
  483.         print "Removing unused Brushes\n";
  484.         print "--------------------------------\n";
  485.         deleteUnusedBrushes();
  486.         print "\n";
  487.     }
  488.  
  489.     print "Scene optimized - check Script Editor for details.\n";
  490. }
  491.  
  492.  
  493. //
  494. //    same as performCleanUpScene, except everything is cleaned up
  495. //
  496. global proc performCleanUpSceneForEverything ()
  497. {
  498.     print "\nClean up database\n";
  499.     print "-----------------\n\n";
  500.  
  501.     deleteInvalidNurbs(0);
  502.     deleteUnusedCommon( "stitchSrf", 0 );
  503.     deleteUnusedCommon( "rebuildSurface", 0 );
  504.     deleteUnusedCommon( "insertKnotSurface", 0 );
  505.     deleteUnusedCommon( "avgNurbsSurfacePoints", 0 );
  506.     deleteUnusedCommon("nurbsCurve", 0);
  507.     deleteUnusedLocators();
  508.     deleteUnusedConstraints();
  509.     deleteUnusedPairBlends();    
  510.     deleteUnusedDeformers();
  511.     deleteUnusedExpressions();
  512.     deleteUnusedCommon("groupId", 1);
  513.     deleteUnusedCommon("animCurve", 0);
  514.     deleteUnusedCommon("snapshot", 1);
  515.     deleteUnusedCommon("unitConversion", 1);
  516.     deleteUnusedCommon("timeToUnitConversion", 1);
  517.     deleteUnusedCommon("unitToTimeConversion", 1);
  518.     MLdeleteUnused();
  519.     clearCache -allNodes;
  520.     deleteEmptyGroups();
  521.     deleteEmptyLayers("Display");
  522.     deleteEmptyLayers("Render");
  523.     deleteUnusedSets();
  524.     deleteUnusedCommon("partition", 0);
  525.     RNdeleteUnused();
  526.     deleteUnusedBrushes();
  527.  
  528.     print "\n";
  529. }
  530.  
  531.  
  532. //
  533. //    option box layout for cleanup
  534. //
  535. global proc cleanUpOptions ()
  536. {
  537.     string $commandName = "cleanUpScene";
  538.     string $callback = ($commandName + "Callback");
  539.     string $setup = ($commandName + "Setup");
  540.  
  541.     string $layout = getOptionBox();
  542.     setParent $layout;
  543.  
  544.     setOptionBoxCommandName($commandName);
  545.  
  546.     string $tabLayout = `tabLayout -scrollable 1`;
  547.     tabLayout -edit
  548.         -tabsVisible false
  549.         -preSelectCommand ("createCleanUpSceneTabUI " + $tabLayout)
  550.         $tabLayout;
  551.     columnLayout -adj true;
  552.         setParent ..;
  553.     tabLayout -edit
  554.         $tabLayout;
  555.  
  556.     createCleanUpSceneTabUI($tabLayout);
  557.  
  558.  
  559.     //  Std buttons for options.
  560.     //
  561.     string $applyBtn = getOptionBoxApplyBtn();
  562.     button -edit -l "Optimize"
  563.         -command ($callback + " " + $tabLayout + " " + 1 + "; performCleanUpScene")
  564.         $applyBtn;
  565.     string $saveBtn = getOptionBoxSaveBtn();
  566.     button -edit
  567.         -command ($callback + " " + $tabLayout + " " + 0 + "; hideOptionBox")
  568.         $saveBtn;
  569.     string $resetBtn = getOptionBoxResetBtn();
  570.     button -edit
  571.         -command ($setup + " " + $tabLayout + " " + 1)
  572.         $resetBtn;
  573.  
  574.     setOptionBoxTitle("Optimize Scene Size Options");
  575.  
  576.     //    Customize the 'Help' menu item text.
  577.     //
  578.     setOptionBoxHelpTag( "OptimizeSceneSize" );
  579.  
  580.     showOptionBox();
  581. }
  582.  
  583.  
  584. global proc createCleanUpSceneTabUI (string $tabLayout)
  585. {
  586.     string $tab[] = `tabLayout -query -childArray $tabLayout`;
  587.     int $currentTabIndex = `tabLayout -query -selectTabIndex $tabLayout`;
  588.  
  589.     if (0 == `columnLayout -query -numberOfChildren $tab[$currentTabIndex-1]`) {
  590.  
  591.         setParent $tab[$currentTabIndex-1];
  592.  
  593.         string $label;
  594.         int $index;
  595.  
  596.         setUITemplate -pushTemplate attributeEditorTemplate;
  597.  
  598.         waitCursor -state 1;
  599.  
  600.         if (1 == $currentTabIndex) {
  601.             checkBoxGrp -ncb 1 -label "Remove Invalid"
  602.                 -label1 "NURBS Surfaces + Curves" nurbsSrfOption;
  603.  
  604.             separator;            
  605.  
  606.             checkBoxGrp -ncb 1 -label "Remove Empty"
  607.                 -label1 "Sets" setsOption;
  608.             checkBoxGrp -ncb 1
  609.                 -label1 "Partitions" partitionOption;
  610.             checkBoxGrp -ncb 1 
  611.                 -label1 "Transforms" transformOption;
  612.             checkBoxGrp -ncb 1 
  613.                 -label1 "Display Layers" displayLayerOption;
  614.             checkBoxGrp -ncb 1 
  615.                 -label1 "Render Layers" renderLayerOption;
  616.  
  617.             separator -w 490;            
  618.  
  619.             checkBoxGrp -ncb 1  -label "Remove Unused"
  620.                 -label1 "Animation Curves" animationCurveOption;
  621.             checkBoxGrp -ncb 1 -label1 "Animation Clips" clipOption;            
  622.             checkBoxGrp -ncb 1 -label1 "Poses" poseOption;
  623.             checkBoxGrp -ncb 1 -label1 "NURBS Curves" -value1 false nurbsCrvOption;
  624.             checkBoxGrp -ncb 1 -label1 "Cached Data" -value1 false cachedOption;
  625.             checkBoxGrp -ncb 1 -label1 "Deformers" deformerOption;
  626.             checkBoxGrp -ncb 1 -label1 "Expressions" -value1 false expressionOption;
  627.             checkBoxGrp -ncb 1 -label1 "GroupID Nodes" groupIDnOption;
  628.             checkBoxGrp -ncb 1 -label1 "Rendering Nodes" shaderOption;
  629.             checkBoxGrp -ncb 1 -label1 "Locators" locatorOption;
  630.             checkBoxGrp -ncb 1 -label1 "Constraints" ptConOption;
  631.             checkBoxGrp -ncb 1 -label1 "Pair Blends" pbOption;            
  632.             checkBoxGrp -ncb 1 -label1 "Snapshot Nodes" snapshotOption;
  633.             checkBoxGrp -ncb 1 -label1 "Unit Conversion Nodes" 
  634.                 unitConversionOption;
  635.             checkBoxGrp -ncb 1 -label1 "Referenced Items" referencedOption;
  636.             checkBoxGrp -ncb 1 -label1 "Brushes" brushOption;
  637.  
  638.             setParent ..;
  639.         }
  640.  
  641.         eval (("cleanUpSceneSetup " + $tabLayout + " " + 0));
  642.  
  643.         waitCursor -state 0;
  644.         setUITemplate -popTemplate;
  645.     }
  646. }
  647.  
  648.  
  649. //
  650. //    intialize the options for cleanup
  651. //
  652. global proc setOptionVars(int $forceFactorySettings)
  653. {
  654.     if ($forceFactorySettings || !`optionVar -exists nurbsSrfOption`)
  655.         optionVar -intValue nurbsSrfOption true;
  656.     if ($forceFactorySettings || !`optionVar -exists nurbsCrvOption`)
  657.         optionVar -intValue nurbsCrvOption false;
  658.     if ($forceFactorySettings || !`optionVar -exists deformerOption`)
  659.         optionVar -intValue deformerOption true;
  660.     if ($forceFactorySettings || !`optionVar -exists poseOption`)
  661.         optionVar -intValue poseOption false;
  662.     if ($forceFactorySettings || !`optionVar -exists clipOption`)
  663.         optionVar -intValue clipOption false;
  664.     if ($forceFactorySettings || !`optionVar -exists expressionOption`)
  665.         optionVar -intValue expressionOption false;
  666.     if ($forceFactorySettings || !`optionVar -exists groupIDnOption`)
  667.         optionVar -intValue groupIDnOption true;
  668.     if ($forceFactorySettings || !`optionVar -exists animationCurveOption`)
  669.         optionVar -intValue animationCurveOption true;
  670.     if ($forceFactorySettings || !`optionVar -exists shaderOption`)
  671.         optionVar -intValue shaderOption true;
  672.     if ($forceFactorySettings || !`optionVar -exists cachedOption`)
  673.         optionVar -intValue cachedOption false;
  674.     if ($forceFactorySettings || !`optionVar -exists transformOption`)
  675.         optionVar -intValue transformOption true;
  676.     if ($forceFactorySettings || !`optionVar -exists displayLayerOption`)
  677.         optionVar -intValue displayLayerOption true;
  678.     if ($forceFactorySettings || !`optionVar -exists renderLayerOption`)
  679.         optionVar -intValue renderLayerOption true;
  680.     if ($forceFactorySettings || !`optionVar -exists setsOption`)
  681.         optionVar -intValue setsOption true;
  682.     if ($forceFactorySettings || !`optionVar -exists partitionOption`)
  683.         optionVar -intValue partitionOption false;
  684.     if ($forceFactorySettings || !`optionVar -exists locatorOption`)
  685.         optionVar -intValue locatorOption false;
  686.     if ($forceFactorySettings || !`optionVar -exists ptConOption`)
  687.         optionVar -intValue ptConOption true;
  688.     if ($forceFactorySettings || !`optionVar -exists pbOption`)
  689.         optionVar -intValue pbOption true;
  690.     if ($forceFactorySettings || !`optionVar -exists snapshotOption`)
  691.         optionVar -intValue snapshotOption true;
  692.     if ($forceFactorySettings || !`optionVar -exists unitConversionOption`)
  693.         optionVar -intValue unitConversionOption true;
  694.     if ($forceFactorySettings || !`optionVar -exists referencedOption`)
  695.         optionVar -intValue referencedOption true;
  696.     if ($forceFactorySettings || !`optionVar -exists brushOption`)
  697.         optionVar -intValue brushOption true;
  698. }
  699.  
  700.  
  701. //
  702. //    callback to set the values based on current settings
  703. //
  704. global proc cleanUpSceneCallback(string $parent, int $doIt)
  705. {
  706.     setParent $parent;
  707.     
  708.     if (`checkBoxGrp -exists nurbsSrfOption`) {
  709.         optionVar -intValue nurbsSrfOption
  710.             `checkBoxGrp -query -value1 nurbsSrfOption`;
  711.     }
  712.     if (`checkBoxGrp -exists nurbsCrvOption`) {
  713.         optionVar -intValue nurbsCrvOption
  714.             `checkBoxGrp -query -value1 nurbsCrvOption`;
  715.     }
  716.     if (`checkBoxGrp -exists deformerOption`) {
  717.         optionVar -intValue deformerOption
  718.             `checkBoxGrp -query -value1 deformerOption`;
  719.     }
  720.     if (`checkBoxGrp -exists poseOption`) {
  721.         optionVar -intValue poseOption
  722.             `checkBoxGrp -query -value1 poseOption`;
  723.     }
  724.     if (`checkBoxGrp -exists clipOption`) {
  725.         optionVar -intValue clipOption
  726.             `checkBoxGrp -query -value1 clipOption`;
  727.     }
  728.     if (`checkBoxGrp -exists expressionOption`) {
  729.         optionVar -intValue expressionOption
  730.             `checkBoxGrp -query -value1 expressionOption`;
  731.     }
  732.     if (`checkBoxGrp -exists groupIDnOption`) {
  733.         optionVar -intValue groupIDnOption
  734.             `checkBoxGrp -query -value1 groupIDnOption`;
  735.     }
  736.     if (`checkBoxGrp -exists animationCurveOption`) {
  737.         optionVar -intValue animationCurveOption
  738.             `checkBoxGrp -query -value1 animationCurveOption`;
  739.     }
  740.     if (`checkBoxGrp -exists shaderOption`) {
  741.         optionVar -intValue shaderOption
  742.             `checkBoxGrp -query -value1 shaderOption`;
  743.     }
  744.     if (`checkBoxGrp -exists cachedOption`) {
  745.         optionVar -intValue cachedOption
  746.             `checkBoxGrp -query -value1 cachedOption`;
  747.     }
  748.     if (`checkBoxGrp -exists transformOption`) {
  749.         optionVar -intValue transformOption
  750.             `checkBoxGrp -query -value1 transformOption`;
  751.     }
  752.     if (`checkBoxGrp -exists displayLayerOption`) {
  753.         optionVar -intValue displayLayerOption
  754.             `checkBoxGrp -query -value1 displayLayerOption`;
  755.     }
  756.     if (`checkBoxGrp -exists renderLayerOption`) {
  757.         optionVar -intValue renderLayerOption
  758.             `checkBoxGrp -query -value1 renderLayerOption`;
  759.     }
  760.     if (`checkBoxGrp -exists setsOption`) {
  761.         optionVar -intValue setsOption
  762.             `checkBoxGrp -query -value1 setsOption`;
  763.     }
  764.     if (`checkBoxGrp -exists partitionOption`) {
  765.         optionVar -intValue partitionOption
  766.             `checkBoxGrp -query -value1 partitionOption`;
  767.     }
  768.     if (`checkBoxGrp -exists locatorOption`) {
  769.         optionVar -intValue locatorOption
  770.             `checkBoxGrp -query -value1 locatorOption`;
  771.     }
  772.     if (`checkBoxGrp -exists ptConOption`) {
  773.         optionVar -intValue ptConOption
  774.             `checkBoxGrp -query -value1 ptConOption`;
  775.     }
  776.     if (`checkBoxGrp -exists pbOption`) {
  777.         optionVar -intValue pbOption
  778.             `checkBoxGrp -query -value1 pbOption`;
  779.     }
  780.     if (`checkBoxGrp -exists snapshotOption`) {
  781.         optionVar -intValue snapshotOption
  782.             `checkBoxGrp -query -value1 snapshotOption`;
  783.     }
  784.     if (`checkBoxGrp -exists unitConversionOption`) {
  785.         optionVar -intValue unitConversionOption
  786.             `checkBoxGrp -query -value1 unitConversionOption`;
  787.     }
  788.     if (`checkBoxGrp -exists referencedOption`) {
  789.         optionVar -intValue referencedOption
  790.             `checkBoxGrp -query -value1 referencedOption`;
  791.     }
  792.     if (`checkBoxGrp -exists brushOption`) {
  793.         optionVar -intValue brushOption
  794.             `checkBoxGrp -query -value1 brushOption`;
  795.     }
  796. }
  797.  
  798.  
  799. //
  800. //    reset the option values
  801. //
  802. global proc cleanUpSceneSetup(string $parent, int $forceFactorySettings)
  803. {
  804.     setOptionVars($forceFactorySettings);
  805.     
  806.     if (`checkBoxGrp -exists nurbsSrfOption`) {
  807.         checkBoxGrp -edit
  808.             -value1 `optionVar -query nurbsSrfOption`
  809.             nurbsSrfOption;
  810.     }
  811.     if (`checkBoxGrp -exists nurbsCrvOption`) {
  812.         checkBoxGrp -edit
  813.             -value1 `optionVar -query nurbsCrvOption`
  814.             nurbsCrvOption;
  815.     }
  816.     if (`checkBoxGrp -exists deformerOption`) {
  817.         checkBoxGrp -edit
  818.             -value1 `optionVar -query deformerOption`
  819.             deformerOption;
  820.     }
  821.     if (`checkBoxGrp -exists clipOption`) {
  822.         checkBoxGrp -edit
  823.             -value1 `optionVar -query clipOption`
  824.             clipOption;
  825.     }
  826.     if (`checkBoxGrp -exists poseOption`) {
  827.         checkBoxGrp -edit
  828.             -value1 `optionVar -query poseOption`
  829.             poseOption;
  830.     }
  831.     if (`checkBoxGrp -exists expressionOption`) {
  832.         checkBoxGrp -edit
  833.             -value1 `optionVar -query expressionOption`
  834.             expressionOption;
  835.     }
  836.     if (`checkBoxGrp -exists groupIDnOption`) {
  837.         checkBoxGrp -edit
  838.             -value1 `optionVar -query groupIDnOption`
  839.             groupIDnOption;
  840.     }
  841.     if (`checkBoxGrp -exists animationCurveOption`) {
  842.         checkBoxGrp -edit
  843.             -value1 `optionVar -query animationCurveOption`
  844.             animationCurveOption;
  845.     }
  846.     if (`checkBoxGrp -exists shaderOption`) {
  847.         checkBoxGrp -edit
  848.             -value1 `optionVar -query shaderOption`
  849.             shaderOption;
  850.     }
  851.     if (`checkBoxGrp -exists cachedOption`) {
  852.         checkBoxGrp -edit
  853.             -value1 `optionVar -query cachedOption`
  854.             cachedOption;
  855.     }
  856.     if (`checkBoxGrp -exists transformOption`) {
  857.         checkBoxGrp -edit
  858.             -value1 `optionVar -query transformOption`
  859.             transformOption;
  860.     }
  861.     if (`checkBoxGrp -exists displayLayerOption`) {
  862.         checkBoxGrp -edit
  863.             -value1 `optionVar -query displayLayerOption`
  864.             displayLayerOption;
  865.     }
  866.     if (`checkBoxGrp -exists renderLayerOption`) {
  867.         checkBoxGrp -edit
  868.             -value1 `optionVar -query renderLayerOption`
  869.             renderLayerOption;
  870.     }
  871.     if (`checkBoxGrp -exists setsOption`) {
  872.         checkBoxGrp -edit
  873.             -value1 `optionVar -query setsOption`
  874.             setsOption;
  875.     }
  876.     if (`checkBoxGrp -exists partitionOption`) {
  877.         checkBoxGrp -edit
  878.             -value1 `optionVar -query partitionOption`
  879.             partitionOption;
  880.     }
  881.     if (`checkBoxGrp -exists locatorOption`) {
  882.         checkBoxGrp -edit
  883.             -value1 `optionVar -query locatorOption`
  884.             locatorOption;
  885.     }
  886.     if (`checkBoxGrp -exists ptConOption`) {
  887.         checkBoxGrp -edit
  888.             -value1 `optionVar -query ptConOption`
  889.             ptConOption;
  890.     }
  891.     if (`checkBoxGrp -exists pbOption`) {
  892.         checkBoxGrp -edit
  893.             -value1 `optionVar -query pbOption`
  894.             pbOption;
  895.     }
  896.     if (`checkBoxGrp -exists snapshotOption`) {
  897.         checkBoxGrp -edit
  898.             -value1 `optionVar -query snapshotOption`
  899.             snapshotOption;
  900.     }
  901.     if (`checkBoxGrp -exists unitConversionOption`) {
  902.         checkBoxGrp -edit
  903.             -value1 `optionVar -query unitConversionOption`
  904.             unitConversionOption;
  905.     }
  906.     if (`checkBoxGrp -exists referencedOption`) {
  907.         checkBoxGrp -edit
  908.             -value1 `optionVar -query referencedOption`
  909.             referencedOption;
  910.     }
  911.     if (`checkBoxGrp -exists brushOption`) {
  912.         checkBoxGrp -edit
  913.             -value1 `optionVar -query brushOption`
  914.             brushOption;
  915.     }
  916. }
  917.  
  918.  
  919. //-------------------------------------------------
  920.  
  921. //
  922. // Some Short delete procs.
  923. //
  924.  
  925. proc int isNodeUsed(string $node, int $minVal)
  926. //
  927. // Description:
  928. //      Function to return whether a node is used in the scene.
  929. //
  930. // Arguments:
  931. //      node    Name of the node to test.
  932. //      minVal  Minimum number of connections the node must have to be
  933. //              considered used (ie. a node must have more than this
  934. //              number to be considered used.
  935. //
  936. // Returns:
  937. //      1   - the node is used by the scene
  938. //      0   - this node doesn't have enough connections, its unused.
  939. //
  940. // Author:
  941. //      cdt (March 2002)
  942. //
  943. {
  944.     int $isUsed = 1;
  945.  
  946.     if ($node != "characterPartition") {
  947.         // sometimes related nodes might delete others on the
  948.         // list, so need to check if the node still exists.
  949.         string $reallyExist[] = `ls $node`;
  950.         
  951.         if (size($reallyExist) != 0) {
  952.             string $connectionList[] = `listConnections $node`;
  953.  
  954.             if (size($connectionList) <= $minVal)
  955.             {
  956.                 $isUsed = 0;
  957.             }
  958.         }
  959.     }
  960.  
  961.     return $isUsed;
  962. }
  963.  
  964. global proc deleteUnusedCommon(string $typ, int $minVal)
  965. {
  966.     int $i;
  967.     string $nodeList[] = `ls -typ $typ`;
  968.  
  969.     for ($i = 0; $i < size($nodeList); $i++) {
  970.         if (!isNodeUsed($nodeList[$i], $minVal)) {
  971.             deleteIfNotReferenced $nodeList[$i];
  972.         }
  973.     }
  974. }
  975.  
  976.  
  977. //
  978. // Delete Unused Sets.
  979. //
  980.  
  981. global proc deleteUnusedSets()
  982. {
  983.     string $sets[] = `ls -sets`;
  984.  
  985.     for( $set in $sets ) {
  986.         if (`objExists $set`) {
  987.             string $elements[] = `sets -q $set`;
  988.             if( `size $elements` < 1 ) {
  989.                 if( $set != "defaultLightSet" && $set != "defaultObjectSet" &&
  990.                     $set != "initialParticleSE" && $set != "initialShadingGroup") {
  991.                     deleteIfNotReferenced( $set );
  992.                 }
  993.             }
  994.         }
  995.     }
  996. }
  997.  
  998. //  ====================== deleteUnusedExpressions ======================
  999. //
  1000. //  Author:         Jonathan Southard
  1001. //  Creation Date:  March, 1999
  1002. //
  1003. //  Description:
  1004. //    Deletes all expression nodes which have no direct connections 
  1005. //  to any of their output attributes.  A unit node with nothing on 
  1006. //  the other side is considered not to be a direct connection, i.e. it is
  1007. //  skipped over.  Note we say "direct" connections.  An expression might 
  1008. //  be part of a connected group of nodes which were cut off from the 
  1009. //  rest of the scene, hence "not used," but this routine
  1010. //  does not attempt to depth-search the network to detect such situations.
  1011. // 
  1012. //  This routine deletes only "expression" nodes, not dynExpressions.  
  1013. //  dynExpressions are built into the particle shapes.
  1014. //
  1015. //  CAUTION: If you have an expression that executes Mel commands but
  1016. //  has no output connections, this routine *will* delete it.  Use cautiously!
  1017. //
  1018. //  INPUT ARGUMENTS
  1019. //      None.
  1020. // 
  1021. //  Return Value: 
  1022. //      int $deleteCount = 
  1023. //           number of expression nodes deleted
  1024. //
  1025. global proc int deleteUnusedExpressions() {
  1026.  
  1027.     int $deletedCount = 0;
  1028.  
  1029.     //  Get a list of all expression nodes.
  1030.     //
  1031.     string $nodeList[];
  1032.     clear( $nodeList );
  1033.     $nodeList = `ls -type expression`;
  1034.  
  1035.     // Iterate through list of nodes
  1036.     //
  1037.     int $i;
  1038.     int $nodeCount = size( $nodeList );
  1039.     for ($i = 0; $i  < $nodeCount; $i++)
  1040.     {
  1041.         // See if this node's "output" attribute has any
  1042.         // outgoing connections.
  1043.         //
  1044.         string $outputs[];
  1045.         clear( $outputs );
  1046.         $outputs = `listConnections -source false -destination true -skipConversionNodes true ($nodeList[$i]+".output")`;
  1047.         if( size( $outputs ) == 0 )        
  1048.         {
  1049.             if( deleteIfNotReferenced( $nodeList[$i] ) ) {
  1050.                 $deletedCount++;
  1051.             }
  1052.         }
  1053.     }
  1054.     return $deletedCount;                        
  1055. }
  1056.  
  1057. global proc deleteUnusedInUnusedHierarchy(string $typ, int $minVal)
  1058. //
  1059. // Description:
  1060. //      For each node of the specified type, delete it if it's unused and
  1061. //      all it's parents are also unused. This will delete only those
  1062. //      nodes of the specified type and will not the unused nodes in
  1063. //      the hierarchy. For example, if all nodes in the hierarchy: "group1
  1064. //      | group2 | curveShape1" are unused and typ is "curveShape"; only
  1065. //      the "curveShape" node will be deleted.
  1066. //
  1067. // Notes:
  1068. //      This method may be desireable over using deleteUnusedCommon in
  1069. //      situations where shape nodes are being cleaned up. For example,
  1070. //      even though a curve shape is unused we should still keep it in
  1071. //      the scene because the user may be using it to assist in picking
  1072. //      the hierarchy (BUG 163067).
  1073. //
  1074. // Author:
  1075. //      cdt (March 2002)
  1076. //
  1077. {
  1078.     string $nodeList[] = `ls -typ $typ`;
  1079.  
  1080.     string $parents[];
  1081.  
  1082.     for ($node in $nodeList) {
  1083.         if (!isNodeUsed($node, $minVal)) {
  1084.             // The shape is unused, check whether its parents are also unused.
  1085.  
  1086.             int $isUsed = 0;
  1087.  
  1088.             clear($parents); // reset, allParents() will append to list.
  1089.             getAllParents($node, $parents);
  1090.  
  1091.             for ($parent in $parents) {
  1092.                 if (isNodeUsed($parent, $minVal)) {
  1093.                     // At least one of the parents is used, keep the shape.
  1094.                     $isUsed = 1;
  1095.                     break;
  1096.                 }
  1097.             }
  1098.  
  1099.             if (!$isUsed) {
  1100.                 deleteIfNotReferenced $node;
  1101.             }
  1102.         }
  1103.     }
  1104. }
  1105.